import 'package:bigegg/data/repository/xmm_remote_repository.dart';
import 'package:bigegg/entity/user/xmm_wall_user.dart';
import 'package:bigegg/entity/xmm_video_info.dart';
import 'package:bigegg/global/user/xmm_account_manager.dart';
import 'package:bigegg/widget/video/xmm_video_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../common/log/xmm_log.dart';
import '../global/routes/xmm_routes.dart';
import '../utils/dialog/xmm_dialog_utils.dart';
import '../utils/xmm_toast_util.dart';
import 'xmm_gift_dialog.dart';

class XmmBusinessDialog {
  static Future<dynamic> showSendGiftDialog(XmmWallUser user) {
    return showDialog(
      context: Get.context!,
      builder: (context) => SimpleDialog(
        insetPadding: EdgeInsets.only(bottom: 150.w),
        titlePadding: EdgeInsets.zero,
        contentPadding: EdgeInsets.zero,
        backgroundColor: Colors.transparent,
        children: [XmmGiftDialog(user)],
      ),
    );
  }

  static void showMoreDialog(String userId) {
    var list = [
      {
        'title': 'Block',
        'onPressed': () async {
          await black(userId);
          XmmRoutes.backMain();
        },
      },
      {
        'title': 'Report',
        'onPressed': () {
          showReportMoreDialog(userId);
        },
      },
    ];
    XmmDialogUtils.showSelectDialog(list);
  }

  static void showReportMoreDialog(String userId) {
    var list = [
      {
        'title': 'Pornographic',
        'onPressed': () async {
          await report(userId, "Pornographic");
        },
      },
      {
        'title': 'False gender',
        'onPressed': () async {
          await report(userId, "False gender");
        },
      },
      {
        'title': 'Fraud',
        'onPressed': () async {
          await report(userId, "Fraud");
        },
      },
      {
        'title': 'Political sensitive',
        'onPressed': () async {
          await report(userId, "Political sensitive");
        },
      },
      {
        'title': 'Other',
        'onPressed': () async {
          await report(userId, "Other");
        },
      },
    ];
    XmmDialogUtils.showSelectDialog(list);
  }

  static Future<void> black(String userId) async {
    try {
      EasyLoading.show();
      await XmmAccountManager.instance.block(userId);
      XmmToastUtils.show("Block Successfully");
    } finally {
      EasyLoading.dismiss();
    }
  }

  static Future<void> report(String userId, String reportType) async {
    try {
      EasyLoading.show();
      XmmLogManger()
          .putLog(XmmLogType.clickEvent, {'page': XmmLogPages.pageReport});
      await XmmRemoteRepository().report(userId, reportType);
      XmmToastUtils.show("Report Successfully");
    } finally {
      EasyLoading.dismiss();
    }
  }

  static showVideoDialog(XmmVideoInfo videoInfo) {
    showDialog(
      context: Get.context!,
      builder: (context) => SimpleDialog(
        titlePadding: EdgeInsets.zero,
        contentPadding: EdgeInsets.zero,
        insetPadding: EdgeInsets.zero,
        backgroundColor: Colors.transparent,
        children: [
          XmmVideoWidget(videoInfo),
        ],
      ),
    );
  }
}
